package cn.xmy.demo01.servlet;

import cn.xmy.demo01.dao.ProductsDao;
import cn.xmy.demo01.pojo.Shops;
import cn.xmy.demo01.service.ProductsService;
import cn.xmy.demo01.service.impl.ProductsServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;


import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
@WebServlet("/MoHoServlet")
public class MoHoServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name=request.getParameter("name");
        ProductsService productsService=new ProductsServiceImpl();

        List<Shops>shops=null;
      try {
          shops=productsService.MoHuAllShops(name);
      } catch (SQLException e) {
          throw new RuntimeException(e);
      } catch (ClassNotFoundException e) {
          throw new RuntimeException(e);
      }
      HttpSession session=request.getSession();
      request.setAttribute("shops",shops);
      request.getRequestDispatcher("MohuIndex.html").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
